package databasetest.zx.com.databasetest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import databasetest.zx.com.databasetest.activity.DBInsertActivity;
import databasetest.zx.com.databasetest.db.UserDBController;
import databasetest.zx.com.databasetest.model.TestThreadModel;
import databasetest.zx.com.databasetest.model.UserModel;

public class MainActivity extends AppCompatActivity {

    Button DBInsertActivity_tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        DBInsertActivity_tv = findViewById(R.id.DBInsertActivity_tv);
        addListener();

//        TestThreadModel mTestThreadModel = new TestThreadModel();
//        TestThread t1 = new TestThread(mTestThreadModel);
//        TestThread t2 = new TestThread(mTestThreadModel);
//        TestThread t3 = new TestThread(mTestThreadModel);
//        t1.start();
//        t2.start();
//        t3.start();
    }

    private void addListener() {
        DBInsertActivity_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, DBInsertActivity.class);
                startActivity(intent);
            }
        });
    }

    class TestThread extends Thread {
        TestThreadModel model;

        public TestThread(TestThreadModel model) {
            this.model = model;
        }

        @Override
        public void run() {
            for (int i = 0; i < 3; i++) {
                // ④每个线程打出3个序列值
                System.out.println("thread[" + Thread.currentThread().getName() + "] --> sn["
                        + model.getNextNum() + "]");
                System.out.println("thread2[" + Thread.currentThread().getName() + "] --> sn["
                        + model.getNextNum2() + "]");
            }
        }
    }

}
